package day05.arrays;

import java.util.Arrays;
import java.util.Comparator;
import java.util.function.ToIntFunction;

/**
 * Description
 * Copyright © 启明星辰 版权所有
 *
 * @author jia_lingqiang
 * @date 2023/9/16
 */
public class PeopleSort {

    public static void main(String[] args) {
        People people1 = new People("zhangsan", 15);
        People people2 = new People("sunyang", 42);
        People[] p = {people1, people2};
        Arrays.sort(p, new Comparator<People>() {
            @Override
            public int compare(People o1, People o2) {
                return o1.getAge() - o2.getAge();

            }
        });

        Arrays.sort(p, (o1, o2) -> o1.getAge() - o2.getAge());

        Arrays.sort(p, Comparator.comparingInt(new ToIntFunction<People>(){
            @Override
            public int applyAsInt(People value) {
                return value.getAge();
            }
        }));

        Arrays.sort(p, Comparator.comparingInt(o -> o.getAge()));

        Arrays.sort(p, Comparator.comparingInt(People::getAge));

        System.out.println(Arrays.toString(p));
    }
}
